package reference;

import java.lang.ref.PhantomReference;
import java.lang.ref.ReferenceQueue;
import java.lang.ref.SoftReference;

/**
 * @author zhangxin
 * @date 2020/8/25
 */
public class Test {


    public static void main(String[] args) {

        ThreadLocal<String> threadLocal  = new ThreadLocal<>();
        threadLocal.set("java");

        System.gc();
        System.runFinalization();

        System.gc();
        System.runFinalization();
        System.gc();
        System.runFinalization();

        System.out.println(threadLocal.get());
    }

    public static void threadLocal(){

    }


        public static void test(){
        TestObject testObject = new TestObject();
        //testObject = null;
        //ReferenceQueue<Object> objectReferenceQueue = new ReferenceQueue<>();
        //PhantomReference<Object> stringPhantomReference = new PhantomReference<>(new String("java"), objectReferenceQueue);
        //
        //System.out.println(objectReferenceQueue.poll());

        System.gc();
        System.gc();
        System.gc();
        System.runFinalization();
        //System.out.println(objectReferenceQueue.poll());

        byte[] bytes = new byte[1024 * 1000];
        for (int i = 0; i < 1000000; i++) {
            bytes[i] = 1;
        }

        //System.out.println(stringPhantomReference.get());

        // soft
        System.out.println("soft---------");
        SoftReference bean = new SoftReference<>(testObject);
        System.gc();
        System.runFinalization();

        bytes = new byte[1024 * 1000];
        for (int i = 0; i < 1000000; i++) {
            bytes[i] = 1;
        }
        System.out.println(bean.get());

        //    strong
    }

}
